<template>
    <view>
        <button @click="onSetTimeCall()">单次的定时器setTimeout</button>
        <button @click="onSetTimeCallxy(userName,password)">带参数的单次的定时器setTimeout</button>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                userName:'ljw',
                password:'666'
            }
        },
        methods: {
            onSetTimeCall(){
                console.log("onSetTimeCall-->");
                //setTimeout(callback,ms,any[])
                setTimeout(()=>{
                    //延时之后要执行的代码
                    console.log("我延时2秒才会打印");
                },2000)
            },
            onSetTimeCallxy(name,pwd){
                console.log("onSetTimeCallxy--> name:"+name+",pwd:"+pwd);
                //console.log("onSetTimeCallxy--> name:"+this.userName+",pwd:"+this.password);
                setTimeout((x,y)=>{
                    console.log("我可以传参数了>x:"+x+",y:"+y);
                },2000,name,pwd)
            }
        }
    }
</script>

<style>

</style>